package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.pandian.entity.PandianJihuaUser;
import cn.stylefeng.guns.modular.pandian.mapper.PandianJihuaUserMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianJihuaUserParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianJihuaUserResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianJihuaUserService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 盘点人员表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2022-01-07
 */
@Service
public class PandianJihuaUserServiceImpl extends ServiceImpl<PandianJihuaUserMapper, PandianJihuaUser> implements PandianJihuaUserService {

    @Override
    public void add(PandianJihuaUserParam param){
        PandianJihuaUser entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianJihuaUserParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianJihuaUserParam param){
        PandianJihuaUser oldEntity = getOldEntity(param);
        PandianJihuaUser newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianJihuaUserResult findBySpec(PandianJihuaUserParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<PandianJihuaUserResult> findListBySpec(PandianJihuaUserParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianJihuaUserParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianJihuaUserParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianJihuaUser getOldEntity(PandianJihuaUserParam param) {
        return this.getById(getKey(param));
    }

    private PandianJihuaUser getEntity(PandianJihuaUserParam param) {
        PandianJihuaUser entity = new PandianJihuaUser();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
